$(function(){
    getCarTeamList();

    $('#side-menu ul').eq(0).addClass('in');

    $('#btn_search').on('click',function(){
        $("#pageNum").val(1);
        getCarTeamList();
    });

    $(document).keydown(function(event){
        if(event.keyCode==13){
            $("#btn_search").click();
        }
    });

});


/**
 *  功能描述：我的车队
 *  请求方式：GET
 *  请求地址：/api/cuser/cars_team
 *  函数名称：getCarTeamList
 */

function getCarTeamList(){
    var id = getUrlParam("id");
    $('input[name=zUserId]').val(id);
    $.ajax({
        url: whole_path+'/api/cuser/cars_team',
        type: 'GET',
        dataType: 'json',
        cache:false,
        data: $('#my_cars_form').serialize(),
        beforeSend:function(data){
            $.progressBar({message:'<p>正在努力加载数据...</p>',modal:true,canCancel:true});
        },
        success:function(data){
            if(data.status == 0) {
                var json = data.data;
                var list = json.result;
                var temp = "";
                if (list != null && list.length>0){
                    $.each(list, function (index, item) {
                        var carsStatus = item.carStatus;
                        switch (carsStatus){
                            case 0:
                                carsStatus = '空车模式'
                                break;
                            case 1:
                                carsStatus = '满载模式'
                                break;
                            case 2:
                                carsStatus = '配货模式'
                                break;
                            default:
                                carsStatus = ''
                        }

                        var carTypes = item.carTypes;
                        switch (carTypes){
                            case 0:
                                carTypes = '自有'
                                break;
                            case 1:
                                carTypes = '外协'
                                break;
                            default:
                                carTypes = ''
                        }

                        temp += '<tr class="gradeA">'
                            + '<td data-title="账号">' + item.userName + '</td>'
                            + '<td data-title="姓名">' + item.realName + '</td>'
                            + '<td data-title="电话">' + item.phoneNumber + '</td>'
                            + '<td data-title="车牌号">' + item.carNumber + '</td>'
                            + '<td data-title="车型">' + item.carModels + '</td>'
                            + '<td data-title="车长">' + item.carLength + '</td>'
                            // + '<td data-title="车重">' + item.carWeight + '</td>'
                            + '<td data-title="车辆状态">' + carsStatus + '</td>'
                            + '<td data-title="出发地">' + (item.startAddress==null?'':item.startAddress) + '</td>'
                            + '<td data-title="目的地">' + (item.destAddress == null?'':item.destAddress) + '</td>'
                            + '<td data-title="剩余装货量">' + (item.goodsNum ==null?'':item.goodsNum) + '</td>'
                            + '<td data-title="车辆类型">' + carTypes + '</td>'
                            + '<td data-title="上报时间">' + (item.reportTime == null?'':timestampFormat(item.reportTime)) + '</td>'
                            + '</tr>';
                    })
                    $('#my_cars_list tbody').html(temp);
                    page('#pagination', json.pagecount, json.pageindex, json.pagesize, getCarTeamList, '#pageNum');

                }else{
                    $.toast("没有查到数据",3000);
                    $('#my_cars_list tbody').html('');
                    if($('#pagination').html().length > 0){
                        $('#pagination').jqPaginator('destroy');
                    }
                }
            }
        },
        complete:function(){
            $.progressBar().close();
        },
        error: function(XMLHttpRequest, textStatus, errorThrown){
            $.toast('服务器未响应,请稍候重试',5000);
        }
    })
}

